#include "header.h"

int main(int argc, char** argv)
{
  work	  wrk;
  params  ctrl;
  char	  s1[80], s2[80];  
  int 	  it = 0, j_out = 0; 
  double  P0, H0;
  FILE 	  *fh = fopen("time_dep.txt", "w");

  init(&argc, argv, &ctrl, &wrk);
  init_prep(&ctrl);
  write_out_surface(&wrk, "test.dat");
  hamiltonian(&ctrl);
  H0 = ctrl.current.H;

  fprintf(fh, "1.time 2. rel error in energy\n\n"); 
  fclose(fh);
  for (int j = 0; j < ctrl.num_iter + 1; j++) {
    if (j >= j_out) { 
      fft(wrk.rho, wrk.Z);
      sprintf(s1,"test_out/z%04d.txt", it);
      write_out_surface(&wrk, s1); 
      sprintf(s1,"test_out/ft%04d.txt", it);
      write_out(wrk.Z, s1); 


      j_out += ctrl.skip; it += 1;

      //fforcing(&ctrl);
      hamiltonian(&ctrl);
      printf("time = %e\tEnergy = %.13e\n", j*(ctrl.dt), ctrl.current.H-H0);
      fh = fopen("time_dep.txt", "a");
      fprintf(fh, "%.13e\t%.13e\n", j*(ctrl.dt), ctrl.current.H - H0);
      fclose(fh);
    }
    rk4(&ctrl); 
  }
}
